package com.greenantmall.bean;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.avos.avoscloud.AVACL;
import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVRole;
import com.greenantmall.utils.UtilTools;

@AVClassName(AntAVObject.CLASS_STOREINFO)
public class StoreInfo extends AntAVObject {

	public static final String ATTR_ADDRESS = "address";// 地址
	public static final String ATTR_SERIALNUMBER = "serialNumber";// 站点代号(便利店以cvs开头，配送站以sp)
	public static final String ATTR_STARTCOST = "startCost";// 服务区
	public static final String ATTR_DELIVERYCOST = "deliveryCost";
	public static final String ATTR_DESCRIP = "descrip";// 服务区
	public static final String ATTR_OPENTIME = "openTime";// 每日开门时间
	public static final String ATTR_SECTIONNUM = "sectionNum";// 服务区
	public static final String ATTR_LEVEL = "level";// 等级，默认为1，只读
	public static final String ATTR_CLOSETIME = "closeTime";// 每日闭店时间
	public static final String ATTR_STATUS = "status";// OPENING,CLOSED，默认为CLOSED，每日由店长手动开启OPENING状态。提前闭店由店长手动确认。服务器每日凌晨会自动将所有的店状态置为CLOSED
	public static final String ATTR_SUBADDR = "subAddr";// 服务区
	public static final String ATTR_STOREID = "userId";// 店铺账号
	public static final String ATTR_STORESTYLE = "storeStyle";// CVS,SP
	public static final String ATTR_UPTOWNS = "uptown";// 配送的小区列表(custom用户可读取)
	public static final String ATTR_PHONE = "phone";//商铺的联系电话
	public static final String ATTR_ISWAITFOROPEN = "isWaitForOpen";
	public static final String ATTR_STORENOTICE = "storeNotice";
	
	// 商店状态
	public static final String STORE_STATUS_CLOSED = "CLOSED";
	public static final String STORE_STATUS_OPENED = "OPENING";
	
	//商店类型
	public static final String STORE_TYPE_SP="SP";
	public static final String STORE_TYPE_CVS="CVS";
	public static final String STORE_TYPE_REST="REST";
	
	
	public static final String ATTR_FIRSTORDERDISCOUNTON = "firstOrderDiscountOn";// boolean,true标志支持首单减免
	public static final String ATTR_FIRSTORDERLIMIT = "firstOrderLimit";// 满足此金额会进行减免
	public static final String ATTR_FIRSTORDERDISCOUNT = "firstOrderDiscount";// 减免金额

	private AVRole customRole;

	public StoreInfo() {
		super();
		setAccessCtrl();
	}

	public StoreInfo(String str) {
		super(str);
		setAccessCtrl();
	}

	public StoreInfo getInstance() {
		return this;
	}

	private int setAccessCtrl() {

		acl = new AVACL();
		acl.setPublicReadAccess(true);// �˴����õ��������˵Ŀɶ�Ȩ��
		acl.setPublicWriteAccess(true);
		this.setACL(acl);

		return 0;
	}

	
	public String getAddress() {
		return this.getString(ATTR_ADDRESS);
	}

	public void setAddress(String userId) {
		this.put(ATTR_ADDRESS,userId);
	}
	
	public String getSerialnumber() {
		return this.getString(ATTR_SERIALNUMBER);
	}

	public void setSerialnumber(String userId) {
		this.put(ATTR_SERIALNUMBER,userId);
	}
	public double getStartcost() {
		return this.getDouble(ATTR_STARTCOST);
	}

	public void setStartcost(double userId) {
		this.put(ATTR_STARTCOST,userId);
	}
	public double getDeliverycost() {
		return this.getDouble(ATTR_DELIVERYCOST);
	}

	public void setDeliverycost(double deliveryCost) {
		this.put(ATTR_DELIVERYCOST, deliveryCost);
	}
	public String getDescrip() {
		return this.getString(ATTR_DESCRIP);
	}

	public void setDescrip(String userId) {
		this.put(ATTR_DESCRIP,userId);
	}
	
	public Date getOpenTime() {
		return UtilTools.parseDateStr("HH:mm", this.getString(ATTR_OPENTIME));
	}
	
	public String getOpenTimeStr() {
    	String str = this.getString(ATTR_OPENTIME);
    	if(str == null) {
    		return "";
    	}
		return str;
	}

	public void setOpenTime(Date userId) {
		this.put(ATTR_OPENTIME,userId);
	}
	
	public Date getCloseTime() {
		return UtilTools.parseDateStr("HH:mm", this.getString(ATTR_CLOSETIME));
	}
	
	public String getCloseTimeStr() {
		String str = this.getString(ATTR_CLOSETIME);
    	if(str == null) {
    		return "";
    	}
		return str;
	}

	public void setCloseTime(Date userId) {
		this.put(ATTR_CLOSETIME,userId);
	}
	
	public String getStoreNotice() {
		return this.getString(ATTR_STORENOTICE);
	}
	
	public void setStoreNotice(String storeNotice) {
		this.put(ATTR_STORENOTICE, storeNotice);
	}
	
	public int getSectionNum() {
		return this.getInt(ATTR_SECTIONNUM);
	}

	public void setSectionNum(int userId) {
		this.put(ATTR_SECTIONNUM,userId);
	}
	
	public boolean isWaitForOpen() {
		return this.getBoolean(ATTR_ISWAITFOROPEN);
	}
	
	public void seWaitForOpen(boolean isWaitForOpen) {
		this.put(ATTR_ISWAITFOROPEN, isWaitForOpen);
	}
	
	public int getLevel() {
		return this.getInt(ATTR_LEVEL);
	}

	public void setLevel(int userId) {
		this.put(ATTR_LEVEL,userId);
	}
	/**
	 * 商店是否开门
	 * @return
	 */
    public boolean isOpen()
    {
        SimpleDateFormat sdf = new SimpleDateFormat("HHmm");
        Date date = new Date();
        date.setTime(System.currentTimeMillis());
        String current = sdf.format(date);
        String open = sdf.format(this.getOpenTime());
        String close = sdf.format(this.getCloseTime());

        double currentTime = Double.parseDouble(current);
        double openTime = Double.parseDouble(open);
        double closeTime = Double.parseDouble(close);

        if (STORE_STATUS_OPENED.equals(this.getString(ATTR_STATUS)) && currentTime > openTime
            && currentTime < closeTime)
        {
            return true;
        }
        return false;
    }

	public void setIsOpen(String userId) {
		this.put(ATTR_STATUS,userId);
	}
	
	public String getSubAddr() {
		return this.getString(ATTR_SUBADDR);
	}

	public void setSubAddr(String userId) {
		this.put(ATTR_SUBADDR,userId);
	}
	
	public String getPhone() {
        return this.getString(ATTR_PHONE);
    }

    public void setPhone(String userId) {
        this.put(ATTR_PHONE,userId);
    }
	
	
	public String getStoreid() {
		return this.getString(ATTR_STOREID);
	}

	public void setStoreid(String userId) {
		this.put(ATTR_STOREID,userId);
	}
	
	public String getStoreStyle() {
		return this.getString(ATTR_STORESTYLE);
	}

	public void setStoreStyle(String userId) {
		this.put(ATTR_STORESTYLE,userId);
	}
	
	public String getUptowns() {
		return this.getString(ATTR_UPTOWNS);
	}

	public void setUptowns(String userId) {
		this.put(ATTR_UPTOWNS,userId);
	}
	
	public boolean isHaveDisaccount() {
		return this.getBoolean(ATTR_FIRSTORDERDISCOUNTON);
	}

	public void setHaveDisaccount(boolean payed) {
		this.put(ATTR_FIRSTORDERDISCOUNTON, payed);
	}

	public double getFirstOrderLimit() {
		return this.getDouble(ATTR_FIRSTORDERLIMIT);
	}

	public void setFirstOrderLimit(double totalCost) {
		this.put(ATTR_FIRSTORDERLIMIT, totalCost);
	}

	public double getFirstOrderDiscount() {
		return this.getDouble(ATTR_FIRSTORDERDISCOUNT);
	}

	public void setFirstOrderDiscount(double totalCost) {
		this.put(ATTR_FIRSTORDERDISCOUNT, totalCost);
	}

}
